import 'package:flutter/material.dart';

class ChildCase extends StatefulWidget {
  const ChildCase({Key? key, required this.count, required this.updateCallBack})
      : super(key: key);
  final int count;

  final Function(int) updateCallBack;
  @override
  _ChildCaseState createState() => _ChildCaseState();
}

class _ChildCaseState extends State<ChildCase> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print("子组件的initState");
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();

    print("子组件的didChangeDependencies");
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    print("子组件的deactivate");
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    print("子组件的dispose");
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text(
          "父组件传递过来的值:${widget.count}",
          style: TextStyle(color: Colors.red, fontSize: 30),
        ),
        ElevatedButton(
            onPressed: () {
              widget.updateCallBack(widget.count + 1);
            },
            child: Text("修改值"))
      ],
    );
  }
}
